package com.kkb.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.pojo.Behospital;
import com.kkb.pojo.Hosregister;
import com.kkb.service.BeHospitalService;
import com.kkb.vo.QueryVO;
import com.kkb.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("hospital")
@ResponseBody
public class BeHospitalController {
    @Resource
    private BeHospitalService beHospitalService;
    //查询所有住院信息
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public ResultVO<Behospital> queryByPage(Integer pageNum, Integer pageSize, QueryVO vo){
        if (pageNum == null || pageNum < 0){
            pageNum = 1;
        }
        if (pageSize == null || pageSize < 0){
            pageSize = 5;
        }
        PageInfo<Behospital> pageInfo = beHospitalService.queryByPage(pageNum, pageSize, vo);
        if (pageInfo.getList().size() != 0 ){
            return new ResultVO<>(pageInfo);
        }
        return new ResultVO<>(404,"数据找不着");
    }
    //添加住院信息
    @RequestMapping(value = "addBeh",method = RequestMethod.POST)
    public ResultVO<Integer> addBeh(Behospital beh){
        Integer add = beHospitalService.add(beh);
        if (add > 0){
            return new ResultVO<>(200,"添加成功");
        }
        return new ResultVO<>(500,"添加失败");
    }
    //修改住院信息
    @RequestMapping(value = "update",method = RequestMethod.PUT)
    public ResultVO<Integer> update(Behospital beh){
        int update = beHospitalService.update(beh);
        if (update>0){
            return new ResultVO<>(200,"信息修改成功");
        }else {
            return new ResultVO<>(500,"信息修改失败");
        }
    }
    //出院批量操作
    @RequestMapping(value = "updateState",method = RequestMethod.GET)
    public ResultVO<Integer> updateState(@RequestParam(value = "ids",required = false) List<Integer> list){
        int i = beHospitalService.updateState(list);
        if ( i > 0 ){
            return new ResultVO<>(200,"办理出院成功");
        }else {
            return new ResultVO<>(500,"办理出院失败");
        }

    }
    //查看详细信息
    @RequestMapping(value = "queryById/{beH_id}",method = RequestMethod.GET)
    public ResultVO<Behospital> queryById(@PathVariable("beH_id") Integer beH_id){
        Behospital behospital = beHospitalService.queryById(beH_id);
        if (behospital != null){
            return new ResultVO<>(behospital);
        }
        return new ResultVO<>(404,"数据丢失了");
    }


}
